Skip to content

Scripts - HRRR - Check that all requested variables are in the grib file #35

Open
brentwilder wants to merge 3 commits into
iSnobal:mainfrom
brentwilder:check-vars
Open

Scripts - HRRR - Check that all requested variables are in the grib file #35
brentwilder wants to merge 3 commits into
iSnobal:mainfrom
brentwilder:check-vars

Conversation

@brentwilder
Copy link
Copy Markdown
Contributor

Addresses #34 . The idea here is to fold it into the existing loop we do which cycles through all of the data sources if there is no data found. Suggested change is if not all HRRR_VARS are found, we delete the file and will automatically download from another source.

@brentwilder brentwilder requested a review from jomey May 29, 2026 20:49
@jomey jomey requested a review from Copilot May 29, 2026 21:03
@brentwilder brentwilder added the Data setup Scripts that aid in getting model data label May 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a post-hoc integrity check to the HRRR download script that confirms every variable listed in HRRR_VARS is present in an existing grib file. When the check fails, the file is removed so the normal archive-fallback path will redownload it from a different source on the next run.

Changes:

  • New check_file_is_valid helper runs wgrib2 -s, parses fields 4-5, and grep-matches each HRRR_VARS entry.
  • check_file_existence now invokes the validator on any non-empty file on disk and returns 3 (triggering the alt-archive pathway) when validation fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/HRRR/download_hrrr.sh
Comment thread scripts/HRRR/download_hrrr.sh Outdated
Comment on lines +125 to +138
check_file_is_valid() {
local file=$1
local metadata
local var
metadata=$(wgrib2 "${file}" -s 2>/dev/null | cut -d: -f4,5)
IFS='|' read -ra vars <<< "${HRRR_VARS}"
for var in "${vars[@]}"; do
if ! echo "${metadata}" | grep -E -q "^${var}(:| )?"; then
return 1
fi
done
return 0
}
export -f check_file_is_valid
Comment thread scripts/HRRR/download_hrrr.sh
Comment thread scripts/HRRR/download_hrrr.sh Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is one where we need to use check_file_existence

Comment thread scripts/HRRR/download_hrrr.sh Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another one here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing to these!

Comment thread scripts/HRRR/download_hrrr.sh
# Write index if it does not exist yet
if [[ -n "${file_idx_data}" ]]; then
echo "${file_idx_data}" > "${file}.idx"
fi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing this on line #136 and then using that as the basis for "grepping". If we have a miss, we will delete it again on line #146

I know that creating this index is quick and this way we would still only do it once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Data setup Scripts that aid in getting model data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants